home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / mapiwin.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  15.5 KB  |  445 lines

  1. /*
  2.  *  M A P I W I N . H
  3.  *
  4.  *  Definitions used by the MAPI Development Team to aid in
  5.  *  developing single-source service providers that run on
  6.  *  both WIN32 and WIN16 platforms.
  7.  *  There are three sections.
  8.  *
  9.  *  The first section defines how to call something that
  10.  *  is available by different methods in WIN16 vs. WIN32.
  11.  *  As such, they are totally new mechanisms.
  12.  *
  13.  *  The second section establishes things that are available
  14.  *  AS-IS in one environment but we have to define for the
  15.  *  other environment.
  16.  *
  17.  *  The third section simply defines a few conventions
  18.  *  (simplifications) for common operations.
  19.  *
  20.  *  Copyright 1986-1996 Microsoft Corporation. All Rights Reserved.
  21.  */
  22.  
  23. /*
  24.  *  Routines are included in the first section to manage per-instance
  25.  *  global variables for DLLs. They assume that all of the DLL's
  26.  *  per-instance global variables live in a single block of memory.
  27.  *  Functions are provided to install and retrieve the correct block of
  28.  *  memory for the current instance.
  29.  *
  30.  *  There are only two functions:
  31.  *
  32.  *      PvGetInstanceGlobals    Call this to get the address of the
  33.  *                              per-instance globals structure.
  34.  *      ScSetinstanceGlobals    Call this to install the
  35.  *                              per-instance globals structure. It
  36.  *                              may fail if the number of instances
  37.  *                              exceeds a certain limit.
  38.  *
  39.  *  The caller is free to choose the name, size, and allocation
  40.  *  method of the per-instance global variables structure.
  41.  *
  42.  *  The WIN32 implementation uses a pointer in the DLL's data
  43.  *  segment. This assumes that the DLL gets a separate instance
  44.  *  of the default data segment per calling process.
  45.  *
  46.  *  The WIN16 implementation uses a fixed array of pointers and a
  47.  *  matching fixed array of keys unique to the calling process.
  48.  */
  49.  
  50. /*
  51.  *  The second section consists largely of Win32 file I/O functions
  52.  *  that are not supported under Win16. These functions are
  53.  *  implemented in mapiwin.c, using DOS calls. Most have limitations
  54.  *  relative to their Win32 counterparts, which are spelled out in
  55.  *  the comments to the source code.
  56.  */
  57.  
  58. #ifndef __MAPIWIN_H__
  59. #define __MAPIWIN_H__
  60. #pragma option push -b
  61.  
  62. #ifdef __BORLANDC__
  63. #  include <pshpack8.h>
  64. #endif
  65.  
  66. #if defined (WIN32) && !defined (_WIN32)
  67. #define _WIN32
  68. #endif
  69.  
  70.  
  71. #include "mapinls.h"
  72.  
  73.  
  74. #ifdef __cplusplus
  75. extern "C" {
  76. #endif
  77.  
  78.  
  79. /********************************/
  80. /*  Our conventions for things  */
  81. /*  we choose to do differently */
  82. /*  on WIN16 vs. WIN32.         */
  83. /********************************/
  84.  
  85. #ifdef  WIN16
  86.  
  87. #define MULDIV(x,y,z)               MulDiv32(x,y,z)
  88. #define IsBadReadPtr(lp,cb)         FBadReadPtr(lp,cb)
  89.  
  90. #define cInstMax                    50
  91. LPVOID FAR PASCAL   PvGetInstanceGlobals(void);
  92. LONG FAR PASCAL     ScSetInstanceGlobals(LPVOID pv);
  93. LONG FAR PASCAL     ScSetVerifyInstanceGlobals(LPVOID pv, DWORD dwPid);
  94. LPVOID FAR PASCAL   PvGetVerifyInstanceGlobals(DWORD dwPid);
  95. LPVOID FAR PASCAL   PvSlowGetInstanceGlobals(DWORD dwPid);
  96. BOOL __export FAR PASCAL FCleanupInstanceGlobals(WORD, DWORD);
  97.  
  98. #elif defined(_MAC) /* !WIN16 */
  99.  
  100. #define MULDIV(x,y,z)               MulDiv(x,y,z)
  101.  
  102. LPVOID FAR PASCAL   PvGetInstanceGlobals(WORD wDataSet);
  103. LONG FAR PASCAL     ScSetInstanceGlobals(LPVOID pv, WORD wDataSet);
  104. LONG FAR PASCAL     ScSetVerifyInstanceGlobals(LPVOID pv, DWORD dwPid,
  105.                         WORD wDataSet);
  106. LPVOID FAR PASCAL   PvGetVerifyInstanceGlobals(DWORD dwPid, DWORD wDataSet);
  107. LPVOID FAR PASCAL   PvSlowGetInstanceGlobals(DWORD dwPid, DWORD wDataSet);
  108. BOOL FAR PASCAL     FCleanupInstanceGlobals(WORD, DWORD);
  109.  
  110. #else   /* !WIN16 */
  111.  
  112. #define MULDIV(x,y,z)               MulDiv(x,y,z)
  113.  
  114. extern LPVOID pinstX;
  115. #define PvGetInstanceGlobals()                  pinstX
  116. #define ScSetInstanceGlobals(_pv)               (pinstX = _pv, 0)
  117. #define PvGetVerifyInstanceGlobals(_pid)        pinstX
  118. #define ScSetVerifyInstanceGlobals(_pv,_pid)    (pinstX = _pv, 0)
  119. #define PvSlowGetInstanceGlobals(_pid)          pinstX
  120.  
  121. #endif  /* WIN16 */
  122.  
  123. #if defined(_WIN32) && !defined(_MAC)
  124. #define szMAPIDLLSuffix     "32"
  125. #elif defined(WIN16) || defined(DOS)
  126. #define szMAPIDLLSuffix     ""
  127. #elif  defined(_MAC)
  128. #define szMAPIDLLSuffix     "M"
  129. #else
  130. #error "Don't know the suffix for DLLs on this platform"
  131. #endif
  132.  
  133. /********************************/
  134. /*  Things missing from one     */
  135. /*  system-provided environment */
  136. /*  or the other.               */
  137. /********************************/
  138.  
  139. #if !defined(_WIN32) 
  140. #define ZeroMemory(pb,cb)           memset((pb),0,(cb))
  141. #define FillMemory(pb,cb,b)         memset((pb),(b),(cb))
  142. #define CopyMemory(pbDst,pbSrc,cb)  do                              \
  143.                                     {                               \
  144.                                         size_t _cb = (size_t)(cb);  \
  145.                                         if (_cb)                    \
  146.                                             memcpy(pbDst,pbSrc,_cb);\
  147.                                     } while (FALSE)
  148. #define MoveMemory(pbDst,pbSrc,cb)  memmove((pbDst),(pbSrc),(cb))
  149.  
  150. #define UNALIGNED
  151.  
  152. #endif
  153.  
  154. #if defined(WIN16) || defined(_MAC)
  155.  
  156. #ifndef _MAC
  157.  
  158. #include <error.h>              /*  for GetLastError() */
  159.  
  160. #endif
  161.  
  162. typedef int                 INT;
  163. typedef unsigned long       ULONG;
  164. typedef short               SHORT;
  165. typedef unsigned short      USHORT;
  166. typedef double              LONGLONG;
  167. typedef double              DWORDLONG;
  168. typedef unsigned char       UCHAR;
  169. typedef unsigned char FAR*  PUCHAR;
  170. typedef int                 BOOL;
  171.  
  172.  
  173. #ifndef _MAC
  174. typedef char                BOOLEAN;
  175.  
  176. #ifndef _FILETIME_
  177. #define _FILETIME_
  178. typedef struct tagFILETIME
  179. {
  180.     DWORD dwLowDateTime;
  181.     DWORD dwHighDateTime;
  182. } FILETIME;
  183. #endif      /* _FILETIME */
  184.  
  185. typedef struct _SYSTEMTIME {
  186.     WORD wYear;
  187.     WORD wMonth;
  188.     WORD wDayOfWeek;
  189.     WORD wDay;
  190.     WORD wHour;
  191.     WORD wMinute;
  192.     WORD wSecond;
  193.     WORD wMilliseconds;
  194. } SYSTEMTIME, *PSYSTEMTIME, FAR *LPSYSTEMTIME;
  195.  
  196. typedef struct _TIME_ZONE_INFORMATION {
  197.     LONG Bias;
  198.     CHAR StandardName[ 32 ];        /* was WCHAR */
  199.     SYSTEMTIME StandardDate;
  200.     LONG StandardBias;
  201.     CHAR DaylightName[ 32 ];        /* was WCHAR */
  202.     SYSTEMTIME DaylightDate;
  203.     LONG DaylightBias;
  204. } TIME_ZONE_INFORMATION, *PTIME_ZONE_INFORMATION, FAR *LPTIME_ZONE_INFORMATION;
  205.  
  206.  
  207. #if defined(DOS) || defined(WIN16)
  208. /* Simulate effect of afx header */
  209. #define __T(x)      x
  210. #define _T(x)       __T(x)
  211. #define TEXT        _T
  212. #endif
  213.  
  214. #define APIENTRY        WINAPI
  215.  
  216. #define SetForegroundWindow         SetActiveWindow
  217.  
  218. #define wsprintfA                   wsprintf
  219. #define GetWindowsDirectoryA        GetWindowsDirectory
  220. #define GetSystemDirectoryA         GetSystemDirectory
  221. #define GetPrivateProfileStringA    GetPrivateProfileString
  222. #define GetPrivateProfileIntA       GetPrivateProfileInt
  223. #define GetProfileStringA           GetProfileString
  224. #define GetModuleFileNameA          GetModuleFileName
  225. #define CharUpperBuffA              CharUpperBuff
  226. #define LoadLibraryA                LoadLibrary
  227. #define lstrcatA                    lstrcat
  228. #define RegisterWindowMessageA      RegisterWindowMessage
  229. #define MAKEINTRESOURCEA            MAKEINTRESOURCE
  230.  
  231. #define WNDCLASSA                   WNDCLASS                                    
  232.  
  233. #endif  /* !_MAC */
  234.  
  235. /* Synchronization */
  236. #define InterlockedIncrement(plong) (++(*(plong)))
  237. #define InterlockedDecrement(plong) (--(*(plong)))
  238.  
  239. #ifndef CreateMutex
  240. #define CreateMutexA    CreateMutex
  241. #define CreateMutexW    CreateMutex
  242. #define CreateMutex(pv, bool, sz)   (INVALID_HANDLE_VALUE)
  243. #endif
  244.  
  245. #define WaitForSingleObject(hObj, dw)   ((void)0)
  246. #define ReleaseMutex(hObj)              ((BOOL)1)
  247. #define CloseMutexHandle(hObj)          TRUE
  248.  
  249. #define CRITICAL_SECTION            ULONG
  250. #define InitializeCriticalSection(_pcs) ((void)0)
  251. #define DeleteCriticalSection(_pcs)     ((void)0)
  252. #define EnterCriticalSection(_pcs)      ((void)0)
  253. #define LeaveCriticalSection(_pcs)      ((void)0)
  254.  
  255. #define MAX_PATH                    260
  256.  
  257. #ifndef _MAC
  258. /*
  259.  *  File Access Modes
  260.  *
  261.  *  The possible combination of file access modes as passed into
  262.  *  the CreateFile() api map to OpenFile() as follows:
  263.  *
  264.  *   GENERIC_READ                       OPEN_ACCESS_READONLY
  265.  *   GENERIC_WRITE                      OPEN_ACCESS_WRITEONLY
  266.  *   GENERIC_READ | GENERIC_WRITE       OPEN_ACCESS_READWRITE
  267.  *
  268.  *   0                                  OPEN_SHARE_DENYREADWRITE
  269.  *   FILE_SHARE_READ                    OPEN_SHARE_DENYWRITE
  270.  *   FILE_SHARE_WRITE                   OPEN_SHARE_DENYREAD
  271.  *   FILE_SHARE_READ | FILE_SHARE_WRITE OPEN_SHARE_DENYNONE
  272.  *
  273.  *  Due to the mappings we cannot pass them through directly,
  274.  *  so we will have to use a conversion within APIs that test
  275.  *  these bits.  It would be best to use the Win32 #defines
  276.  *  for these flags and convert as needed in the APIs.
  277.  */
  278. #define GENERIC_READ                (0x80000000) /* from WINNT.H */
  279. #define GENERIC_WRITE               (0x40000000) /* from WINNT.H */
  280. #define FILE_SHARE_READ             (0x00000001) /* from WINNT.H */
  281. #define FILE_SHARE_WRITE            (0x00000002) /* from WINNT.H */
  282. #endif  /* _MAC */
  283.  
  284. #define FILE_FLAG_SEQUENTIAL_SCAN   0x08000000
  285.  
  286. #define CREATE_NEW          1
  287. #define CREATE_ALWAYS       2
  288. #define OPEN_EXISTING       3
  289. #define OPEN_ALWAYS         4
  290. #define TRUNCATE_EXISTING   5
  291.  
  292. #ifndef _MAC
  293. #define INVALID_HANDLE_VALUE        ((HANDLE)(-1))
  294. #define DELETE                      0x00010000L
  295.  
  296. #define FILE_BEGIN                  0
  297. #define FILE_CURRENT                1
  298. #define FILE_END                    2
  299. #endif
  300.  
  301. #define FILE_ATTRIBUTE_READONLY         0x00000001
  302. #define FILE_ATTRIBUTE_HIDDEN           0x00000002
  303. #define FILE_ATTRIBUTE_SYSTEM           0x00000004
  304. #define FILE_ATTRIBUTE_DIRECTORY        0x00000010
  305. #define FILE_ATTRIBUTE_ARCHIVE          0x00000020
  306. #define FILE_ATTRIBUTE_NORMAL           0x00000080
  307. #define FILE_ATTRIBUTE_TEMPORARY        0x00000100
  308.  
  309. #define FILE_FLAG_WRITE_THROUGH     0x80000000
  310. #define FILE_FLAG_RANDOM_ACCESS     0x10000000
  311.  
  312. #ifndef _MAC
  313. typedef struct _WIN32_FIND_DATA {
  314.     DWORD       dwFileAttributes;
  315.     FILETIME    ftCreationTime;
  316.     FILETIME    ftLastAccessTime;
  317.     FILETIME    ftLastWriteTime;
  318.     DWORD       nFileSizeHigh;
  319.     DWORD       nFileSizeLow;
  320.     DWORD       dwReserved0;
  321.     DWORD       dwReserved1;
  322.     CHAR        cFileName[ MAX_PATH ];
  323.     CHAR        cAlternateFileName[ 16 ];
  324. } WIN32_FIND_DATA, *PWIN32_FIND_DATA, *LPWIN32_FIND_DATA;
  325.  
  326. #define TIME_ZONE_ID_INVALID        0xFFFFFFFF
  327. #endif
  328. #define TIME_ZONE_ID_UNKNOWN        0
  329. #define TIME_ZONE_ID_STANDARD       1
  330. #define TIME_ZONE_ID_DAYLIGHT       2
  331.  
  332.  
  333.  
  334. DWORD WINAPI    GetLastError(void);
  335. DWORD WINAPI    GetFileAttributes(LPCSTR lpFileName);
  336. DWORD WINAPI    GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
  337. BOOL WINAPI     GetFileTime(HANDLE hFile, FILETIME FAR *lpftCreation,
  338.                 FILETIME FAR *lpftLastAccess, FILETIME FAR *lpftLastWrite);
  339. BOOL WINAPI     SetFileTime(HANDLE hFile, const FILETIME FAR *lpftCreation,
  340.                 const FILETIME FAR *lpftLastAccess,
  341.                 const FILETIME FAR *lpftLastWrite);
  342. #ifndef _MAC
  343. /*  IsTask can crash - here's a safer one.  */
  344. BOOL WINAPI     FIsTask(HTASK hTask);
  345.  
  346. HANDLE WINAPI   CreateFile(LPCSTR lpFileName, DWORD dwDesiredAccess,
  347.                 DWORD dwShareMode, LPVOID lpSecurityAttributes,
  348.                 DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
  349.                 HANDLE hTemplateFile);
  350. BOOL WINAPI     ReadFile(HANDLE hFile, LPVOID lpBuffer,
  351.                 DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead,
  352.                 LPVOID lpOverlapped);
  353. BOOL WINAPI     WriteFile(HANDLE hFile, LPCVOID lpBuffer,
  354.                 DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten,
  355.                 LPVOID lpOverlapped);
  356. #endif
  357. DWORD WINAPI    SetFilePointer(HANDLE hFile, LONG lDistanceToMove,
  358.                 LONG FAR *lpDistanceToMoveHigh, DWORD dwMoveMethod);
  359. BOOL WINAPI     SetEndOfFile(HANDLE hFile);
  360. BOOL WINAPI     CloseHandle(HANDLE hObject);
  361. DWORD WINAPI    GetTempPath(DWORD nBufferLength, LPSTR lpBuffer);
  362. UINT WINAPI     GetTempFileName32 (LPCSTR lpPathName, LPCSTR lpPrefixString,
  363.                 UINT uUnique, LPSTR lpTempFileName);
  364. BOOL WINAPI     DeleteFile(LPCSTR lpFileName);
  365. #ifndef _MAC
  366. BOOL WINAPI     CreateDirectory(LPCSTR lpPathName, LPVOID lpSecurityAttributes);
  367. #endif
  368. BOOL WINAPI     RemoveDirectory(LPCSTR lpPathName);
  369. BOOL WINAPI     CopyFile(LPCSTR szSrc, LPCSTR szDst, BOOL fFailIfExists);
  370. BOOL WINAPI     MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName);
  371. HANDLE WINAPI   FindFirstFile(LPCSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData);
  372. BOOL WINAPI     FindNextFile(HANDLE hFindFile, LPWIN32_FIND_DATA lpFindFileData);
  373. BOOL WINAPI     FindClose(HANDLE hFindFile);
  374. DWORD WINAPI    GetFullPathName(LPCSTR lpFileName, DWORD nBufferLength,
  375.                 LPSTR lpBuffer, LPSTR *lpFilePart);
  376. void WINAPI     Sleep(DWORD dwMilliseconds);
  377. LONG WINAPI     CompareFileTime(const FILETIME FAR *, const FILETIME FAR *);
  378. BOOL WINAPI     LocalFileTimeToFileTime(const FILETIME FAR *, FILETIME FAR *);
  379. BOOL WINAPI     FileTimeToLocalFileTime(const FILETIME FAR *, FILETIME FAR *);
  380. BOOL WINAPI     FileTimeToSystemTime(const FILETIME FAR *, SYSTEMTIME FAR *);
  381. BOOL WINAPI     SystemTimeToFileTime(const SYSTEMTIME FAR *, FILETIME FAR *);
  382. void WINAPI     GetSystemTime(SYSTEMTIME FAR *);
  383. void WINAPI     GetLocalTime(SYSTEMTIME FAR *);
  384. BOOL WINAPI     FileTimeToDosDateTime(const FILETIME FAR * lpFileTime,
  385.                 WORD FAR *lpFatDate, WORD FAR *lpFatTime);
  386. BOOL WINAPI     DosDateTimeToFileTime(WORD wFatDate, WORD wFatTime,
  387.                 FILETIME FAR * lpFileTime);
  388. DWORD WINAPI    GetTimeZoneInformation(
  389.                 LPTIME_ZONE_INFORMATION lpTimeZoneInformation);
  390. BOOL WINAPI     SetTimeZoneInformation(
  391.                 const TIME_ZONE_INFORMATION FAR *lpTimeZoneInformation);
  392.  
  393. DWORD WINAPI    GetCurrentProcessId(void);
  394. long WINAPI     MulDiv32(long, long, long);
  395. #ifndef _MAC
  396. BOOL WINAPI     FBadReadPtr(const void FAR* lp, UINT cb);
  397. #endif
  398.  
  399. #else   /* !WIN16 */
  400.  
  401. /* Remaps GetTempFileName32() to the real 32bit version */
  402.  
  403. #define GetTempFileName32(_szPath,_szPfx,_n,_lpbuf) GetTempFileName(_szPath,_szPfx,_n,_lpbuf)
  404.  
  405. #define CloseMutexHandle    CloseHandle
  406.  
  407. #endif  /* !WIN16 */
  408.  
  409.  
  410. #ifdef _MAC
  411. #define CRITICAL_SECTION            ULONG
  412. #define InitializeCriticalSection(_pcs) ((void)0)
  413. #define DeleteCriticalSection(_pcs)     ((void)0)
  414. #define EnterCriticalSection(_pcs)      ((void)0)
  415. #define LeaveCriticalSection(_pcs)      ((void)0)
  416. #endif
  417.  
  418. /********************************/
  419. /*  Our private conventions     */
  420. /*  (common to WIN16/WIN32)     */
  421. /********************************/
  422.  
  423. #define Cbtszsize(_a)   ((lstrlen(_a)+1)*sizeof(TCHAR))
  424. #define CbtszsizeA(_a)  ((lstrlenA(_a) + 1))
  425. #define CbtszsizeW(_a)  ((lstrlenW(_a) + 1) * sizeof(WCHAR))
  426. #define HexCchOf(_s)    (sizeof(_s)*2+1)
  427. #define HexSizeOf(_s)   (HexCchOf(_s)*sizeof(TCHAR))
  428.  
  429. BOOL WINAPI IsBadBoundedStringPtr(const void FAR* lpsz, UINT cchMax);
  430.  
  431. /* FUTURE - obsolete. OLE2 no longer contains these */
  432. #define GetSCode                    GetScode
  433. #define ReportResult(_a,_b,_c,_d)   ResultFromScode(_b)
  434.  
  435. #ifdef __cplusplus
  436. }
  437. #endif
  438.  
  439. #ifdef __BORLANDC__
  440. #  include <poppack.h>
  441. #endif
  442.  
  443. #pragma option pop
  444. #endif /* __MAPIWIN_H__ */
  445.